package com.loanly.controller;

import java.util.List;


import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.classic.*;
//import org.hibernate.Session;
 
import com.loanly.model.Platform;
import com.loanly.util.HibernateUtil;
 
public class PlatformManager extends HibernateUtil {
 
    public Platform add(Platform platform) {
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        session.beginTransaction();
//        platform.setPlatformName("121");
        session.save(platform);
        session.getTransaction().commit();
        return platform;
    }
    public Platform delete(Long id) {
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        session.beginTransaction();
        Platform platform = (Platform) session.load(Platform.class, id);
        if(null != platform) {
            session.delete(platform);
        }
        session.getTransaction().commit();
        return platform;
    }
 
    public List<Platform> list() {
         
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        session.beginTransaction();
        List<Platform> platforms = null;
        try {
             
        	platforms = (List<Platform>)session.createQuery("from Platform").list();
             
        } catch (HibernateException e) {
            e.printStackTrace();
            session.getTransaction().rollback();
        }
        session.getTransaction().commit();
        return platforms;
    }
}